<?php

namespace App\Transformers;

use App\Models\ProductPes;
use App\Models\VendingMachine;
use League\Fractal\TransformerAbstract;

class ProductPesTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['product', 'warehouse'];

    public function transform(ProductPes $productPes)
    {
        return [
            'id'           => $productPes->id,
            'production_date'      => $productPes->production_date,
            'expiration_date'      => $productPes->expiration_date,
            'stock' => $productPes->stock,
            'registered_stock'     => $productPes->registered_stock,
            'is_sold_out_checked'      => $productPes->is_sold_out_checked,
            'product_id'      => $productPes->product_id,
            'warehouse_id'      => $productPes->warehouse_id,
            'created_at'   => (string) $productPes->created_at,
            'updated_at'   => (string) $productPes->updated_at,
        ];
    }

    public function includeUser(ProductPes $productPes)
    {
        return $this->item($productPes->product, new ProductTransformer());
    }

    public function includeWarehouse(VendingMachine $vendingMachine)
    {
        return $this->item($vendingMachine->warehouse, new WarehouseTransformer());
    }
}
